#用aiohttp作框架时写的，自动注册路由的代码片段
#sanic, flask


#自动注册
for dirs in os.listdir(r'./admin'):
    if os.path.isdir('./admin/'+dirs) and dirs not in ['__pycache__','static']:
        mod = getattr(__import__('admin.'+dirs,globals(),locals(),['views']),'views')
        for attr in dir(mod):
            if attr.startswith('_'):
                continue
            fn = getattr(mod, attr)
            if callable(fn):
                #get注册
                path = getattr(fn, '__getroute__', None)
                if path:
                    app.router.add_get(path,fn)
                #post注册
                path = getattr(fn, '__postroute__', None)
                if path:
                    app.router.add_post(path,fn)
